﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class UserDelForm : Form
    {
        public UserDelForm()
        {
            InitializeComponent();
        }

        private void clearall()
        {
            this.textBox1.Text = "";
            this.textBox2.Text = "";
            this.textBox3.Text = "";
            this.textBox4.Text = "";
            this.textBox5.Text = "";
            this.textBox6.Text = "";
            this.textBox7.Text = "";
            this.textBox8.Text = "";
            this.textBox9.Text = "";
            this.textBox10.Text = "";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int userid = Int32.Parse(this.textBox1.Text);
            MONITOR_DBDataContext dbcontext = new MONITOR_DBDataContext();

            var query =  from c in dbcontext.tb_user
                         where c.ID == userid
                         select c;

            if (query.Count() == 0)
            {
                MessageBox.Show("要删除的用户不存在");
                return;
            }

            this.textBox2.Text = query.First().Name;
            this.textBox9.Text = query.First().sex;
            this.textBox10.Text = query.First().Role;
            this.textBox3.Text = query.First().ID.ToString();
            this.textBox11.Text = query.First().Birthday.ToString();
            this.textBox4.Text = query.First().Phone;
            this.textBox5.Text = query.First().email;
            this.textBox6.Text = query.First().Workaddress;
            this.textBox7.Text = query.First().Homeaddress;
            this.textBox8.Text = query.First().Comment;

            UserDelConfirmForm f = new UserDelConfirmForm(userid);
            f.ShowDialog();

            this.clearall();

        }

      
    }
}
